<template>
  <div class="app-container">

    <div class="card-wrap padding20 flex">

      <div v-for="(item, index) in tabs" :key="index"
           @click="tabs.forEach((item, i)=>{item.check = index == i})"
           :class="item.check?'tab-active':'tab-normal'">
        {{item.name}}({{ item.count }})
      </div>

    </div>

    <SearchContent :queryParams="queryParams" @query="handleQuery" @reset="resetQuery">

      <el-col :span="6">
        <el-form-item label="审核状态:" prop="memberType">
          <el-select v-model="form.memberType" clearable>
            <template v-for="dict in dict.type.sys_order_source">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="认领状态:" prop="memberType">
          <el-select v-model="form.memberType" clearable>
            <template v-for="dict in dict.type.sys_order_source">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="业务单号:" prop="memberName">
          <el-input v-model="queryParams.memberName" clearable placeholder="请输入业务单号"></el-input>
        </el-form-item>
      </el-col>

    </SearchContent>

    <div class="card-wrap padding20" :model="queryParams" ref="queryForm" label-width="86px">
      <div class="table-title-wrap justify-end">
        <el-button type="primary" plain size="mini"
                   v-hasPermi="['demo:demo:add']">导出</el-button>
        <el-button type="primary" plain size="mini" @click="handleDetail"
                   v-hasPermi="['demo:demo:add']">审核详情</el-button>
      </div>

      <el-table v-loading="loading" :data="dataList" border>

        <el-table-column label="ID" align="center" prop="tagId" />
        <el-table-column label="标签名称" align="center" prop="tagName" />
        <el-table-column label="标签描述" align="center" prop="tagRemark" />
        <el-table-column label="操作" align="center" fixed="left">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
                       v-hasPermi="['demo:demo:edit']">编辑</el-button>
            <el-button size="mini" type="text" @click="handleDelete(scope.row)"
                       v-hasPermi="['demo:demo:edit']">删除</el-button>

          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getList" />
    </div>


    <!-- 添加或修改测试单表对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="45%">
      <el-form ref="form" :rules="rules" :model="form" label-width="120px">

        <el-row >
          <el-col :span="20">
            <el-form-item label="客户名称:" prop="tagName">
              <el-input v-model="form.contactPhone" clearable placeholder="请输入客户名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="税号:" prop="tagName">
              <el-input v-model="form.contactPhone" clearable placeholder="请输入税号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="开户银行:" prop="tagName">
              <el-input v-model="form.contactPhone" clearable placeholder="请输入开户银行"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="账户:" prop="tagName">
              <el-input v-model="form.contactPhone" clearable placeholder="请输入账户"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="地址:" prop="tagName">
              <el-input v-model="form.contactPhone" clearable placeholder="请输入地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="联系电话:" prop="tagName">
              <el-input v-model="form.contactPhone" clearable placeholder="请输入联系电话"></el-input>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" >
        <el-button @click="cancel">{{ isNew ? '取消' : '关闭' }}</el-button>
        <el-button :loading="buttonLoading" type="primary" @click="submitForm" v-if="isNew">确 定</el-button>
      </div>
    </el-dialog>

    <!--    共用额度客户-->
    <el-dialog title="共用额度客户" :visible.sync="publicOpen" append-to-body width="45%">
      <el-form ref="publicForm" :rules="publicRules" :model="publicForm" label-width="120px">

        <el-row >
          <el-col :span="20">
            <el-form-item label="客户名称:" prop="contactPhone">
              <el-input v-model="publicForm.contactPhone" clearable placeholder="请输入客户名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="共用额度客户:" prop="intentionLevel">
              <el-select v-model="publicForm.intentionLevel" clearable style="width: 100%">
                <template v-for="dict in dict.type.sys_order_source">
                  <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
                </template>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="20">
            <el-form-item label="描述:" prop="remark">

              <el-input v-model="publicForm.remark"
                        type="textarea"
                        :rows="2"
                        clearable placeholder="请输入描述"></el-input>

            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" >
        <el-button @click="publicCancel">{{ isNew ? '取消' : '关闭' }}</el-button>
        <el-button :loading="publicLoading" type="primary" @click="submitForm" v-if="isNew">确 定</el-button>
      </div>
    </el-dialog>

    <!--    共用额度查看-->
    <el-dialog title="共用额度客户" :visible.sync="quotaOpen" append-to-body width="80%">
      <el-table v-loading="quotaloading" :data="quotaList" border>

        <el-table-column label="ID" align="center" prop="tagId" />
        <el-table-column label="标签名称" align="center" prop="tagName" />
        <el-table-column label="标签描述" align="center" prop="tagRemark" />

      </el-table>

      <pagination v-show="quotaTotal > 0" :total="quotaTotal" :page.sync="quotaParams.pageNum" :limit.sync="quotaParams.pageSize"
                  @pagination="getQuotaList" />
    </el-dialog>


  </div>
</template>

<script>
// import { getModelData} from "@/api/zcwh/vehicleModelApi";
// import { getToken } from "@/utils/auth";
// import EInput from "../../components/from_table/EInput.vue";
// import ESelect from "../../components/from_table/ESelect.vue";
// import SearchMixin from '@/mixin/index';
import SearchContent from "@/components/SearchContent/index.vue";
import {delModel} from "@/api/zcwh/vehicleModelApi";

export default {
  // name: "VehicleModelList",
  components: {
    // 'e-input': EInput,
    SearchContent
    // 'e-select': ESelect,
  },
  dicts: ['sys_order_source'],
  // mixins:[SearchMixin],
  data() {
    return {
      //按钮loading
      buttonLoading: false,
      publicLoading: false,
      quotaloading: false,
      // 遮罩层
      loading: true,
      isNew:true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      publicOpen: false,
      quotaOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberName:'',
        originType:'',
        intentionLevel:'',
        memberType:'',
        clueType:'',
        busRange:'',
      },

      total: 0,
      dataList: [],
      quotaTotal: 0,
      quotaList:[],
      quotaParams:{
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        tagName: "",
        remark: "",
      },
      publicForm:{

      },
      // 表单校验
      rules: {
        tagName: [
          { required: true, message: "标签名称不能为空", trigger: "blur" }
        ],
      },
      // 表单校验
      publicRules: {
        tagName: [
          { required: true, message: "标签名称不能为空", trigger: "blur" }
        ],
      },
      tabs:[{
        name:'全部',
        count:12,
        check:true
      },{
        name:'司机审核',
        count:23,
        check:false
      },{
        name:'还车审核',
        count:97,
        check:false
      },{
        name:'保险审核',
        count:2,
        check:false
      },{
        name:'信审',
        count:1,
        check:false
      }
      ]
    };
  },
  created() {
  },
  methods: {
    /** 查询测试单表列表 */
    getList() {
      this.loading = true;


      getModelData(this.queryParams).then(res => {
        if (res.code == "200") {
          const { rows, total } = res
          this.dataList = rows
          this.total = total
          this.loading = false;
        }

      });
    },
    getQuotaList(){

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    publicCancel() {
      this.publicOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tagName: "",
        remark: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        memberName:'',
        originType:'',
        intentionLevel:'',
        memberType:'',
        clueType:'',
        busRange:'',
      },
        // this.resetForm("queryForm");
        this.handleQuery();
    },

    /** 新增操作 */
    handleAdd() {
      // this.reset();
      // this.open = true;
      // this.isNew = true
      // this.title = "新增标签";

      this.$router.push({
        name: 'memberAdd',
        // query: {orderNo: row.orderNo}
      })

    },

    /** 转移 */
    handleTransfer() {
      this.reset();
      this.open = true;
      // this.isNew = true
      this.title = "开票信息";

    },

    handlePublic() {
      this.reset();
      this.publicOpen = true;
      // this.isNew = true

    },

    handleQuota() {
      this.reset();
      this.quotaOpen = true;
      // this.isNew = true

    },

    handleDetail() {
      this.$router.push({
        name: 'driverExamDetail',
        // query: {orderNo: row.orderNo}
      })

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.isNew = true
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      // getCarBasic(id).then(response => {
      //
      //   this.loading = false;
      //   this.form = response.data;
      //   this.form.maxRegYear = response.data.maxRegYear + ""
      //   this.form.minRegYear = response.data.minRegYear + ''
      //   this.form.stopMakeYear = response.data.stopMakeYear + ''
      //   this.form.brandId = response.data.carBrandId
      //   this.form.seriesId = response.data.carSeriesId
      //   this.form.seriesGroupId = response.data.carSeriesGroupId
      //
      //   this.getSeriesNames(this.form.brandId)
      //
      //
      //   this.getSeriesGroup({ brandName: this.form.brandName, carBrandId: this.form.brandId })
      //   this.open = true;
      //   this.title = "编辑";
      //
      //
      // });
      this.$forceUpdate();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否删除？').then(() => {
        this.loading = true;
        return delModel(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id) {
            updateCar(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            carBrandAdd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },

  }
};
</script>


<style lang="scss" scoped>
.pagination-container{
  padding: 0 20px 50px !important;
}


.form-dialog {
  ::v-deep .el-dialog__header {
    padding: 10px 20px;
    border-bottom: 1px solid #DCDFE6;

    .el-dialog__headerbtn {
      top: 15px;
    }
  }

  .box-card {
    margin-bottom: 20px;

    .card-title {
      font-size: 16px;
      position: relative;
      margin-left: 8px;
      padding: 0;
    }

    .card-title::after {
      content: '';
      width: 4px;
      height: 18px;
      background-color: aqua;
      display: block;
      position: absolute;
      left: -12px;
      top: 2px;
    }
  }

}
</style>
